package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import org.testng.annotations.Test;

import com.example.utils.SortedListOf;

import static com.example.fw.ContactHelper.CREATION;

public class AddNewContactTests extends TestBase {
	
  @Test(dataProvider = "randomValidContactGenerator")
  public void testNewContactCreationWithValidData(ContactData contact) throws Exception {

	app.navigateTo().mainPage();  
	
	//save old state
	
	SortedListOf<ContactData> oldList =  app.getContactHelper().getContacts();
	
	//actions
    app.getContactHelper()
    		.initContactCreation()
			.fillContactForm(contact, CREATION)
			.submitContactCreation()
			.returnToHomePage(); 
    
    //save new state
    
    SortedListOf<ContactData> newList =  app.getContactHelper().getContacts();
    
    //compare states
    assertThat(newList, equalTo(oldList.withAdded(contact)));
    
  }
  
}
